$services->getExternalStoreAccess(),
$services->getMainWANObjectCache(),
new ServiceOptions( BlobStoreFactory::CONSTRUCTOR_OPTIONS,
- $services->getMainConfig() ),
- $services->getContentLanguage()
+ $services->getMainConfig() )
);
},
namespace MediaWiki\Storage;
-use Language;
use MediaWiki\Config\ServiceOptions;
use WANObjectCache;
use Wikimedia\Rdbms\ILBFactory;
*/
private $options;
- /**
- * @var Language
- */
- private $contLang;
-
/**
* @var array
* @since 1.34
ILBFactory $lbFactory,
ExternalStoreAccess $extStoreAccess,
WANObjectCache $cache,
- ServiceOptions $options,
- Language $contLang
+ ServiceOptions $options
) {
$options->assertRequiredOptions( self::CONSTRUCTOR_OPTIONS );
$this->extStoreAccess = $extStoreAccess;
$this->cache = $cache;
$this->options = $options;
- $this->contLang = $contLang;
}
/**
$store->setUseExternalStore( $this->options->get( 'DefaultExternalStore' ) !== false );
if ( $this->options->get( 'LegacyEncoding' ) ) {
- $store->setLegacyEncoding( $this->options->get( 'LegacyEncoding' ), $this->contLang );
+ $store->setLegacyEncoding( $this->options->get( 'LegacyEncoding' ) );
}
return $store;
use IDBAccessObject;
use IExpiringStore;
use InvalidArgumentException;
-use Language;
use MWException;
use StatusValue;
use WANObjectCache;
use ExternalStoreAccess;
use Wikimedia\Assert\Assert;
+use Wikimedia\AtEase\AtEase;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\ILoadBalancer;
*/
private $legacyEncoding = false;
- /**
- * @var Language|null
- */
- private $legacyEncodingConversionLang = null;
-
/**
* @var boolean
*/
}
/**
- * @return Language|null The locale to use when decoding from a legacy encoding, or null
- * if handling of legacy encoding is disabled.
+ * @deprecated since 1.34 No longer needed
+ * @return null
*/
public function getLegacyEncodingConversionLang() {
- return $this->legacyEncodingConversionLang;
+ wfDeprecated( __METHOD__ );
+ return null;
}
/**
+ * Set the legacy encoding to assume for blobs that do not have the utf-8 flag set.
+ *
+ * @note The second parameter, Language $language, was removed in 1.34.
+ *
* @param string $legacyEncoding The legacy encoding to assume for blobs that are
* not marked as utf8.
- * @param Language $language The locale to use when decoding from a legacy encoding.
*/
- public function setLegacyEncoding( $legacyEncoding, Language $language ) {
+ public function setLegacyEncoding( $legacyEncoding ) {
Assert::parameterType( 'string', $legacyEncoding, '$legacyEncoding' );
$this->legacyEncoding = $legacyEncoding;
- $this->legacyEncodingConversionLang = $language;
}
/**
}
// Needed to support old revisions left over from from the 1.4 / 1.5 migration.
- if ( $blob !== false && $this->legacyEncoding && $this->legacyEncodingConversionLang
+ if ( $blob !== false && $this->legacyEncoding
&& !in_array( 'utf-8', $blobFlags ) && !in_array( 'utf8', $blobFlags )
) {
# Old revisions kept around in a legacy encoding?
# Upconvert on demand.
# ("utf8" checked for compatibility with some broken
# conversion scripts 2008-12-30)
- $blob = $this->legacyEncodingConversionLang->iconv( $this->legacyEncoding, 'UTF-8', $blob );
+ # Even with //IGNORE iconv can whine about illegal characters in
+ # *input* string. We just ignore those too.
+ # REF: https://bugs.php.net/bug.php?id=37166
+ # REF: https://phabricator.wikimedia.org/T18885
+ AtEase::suppressWarnings();
+ $blob = iconv( $this->legacyEncoding, 'UTF-8//IGNORE', $blob );
+ AtEase::restoreWarnings();
}
return $blob;
use HashBagOStuff;
use IDBAccessObject;
use InvalidArgumentException;
-use Language;
use MediaWiki\Linker\LinkTarget;
use MediaWiki\MediaWikiServices;
use MediaWiki\Revision\IncompleteRevisionException;
$lb = $services->getDBLoadBalancer();
$access = $services->getExternalStoreAccess();
$blobStore = new SqlBlobStore( $lb, $access, $cache );
- $blobStore->setLegacyEncoding( 'windows-1252', Language::factory( 'en' ) );
+ $blobStore->setLegacyEncoding( 'windows-1252' );
$factory = $this->getMockBuilder( BlobStoreFactory::class )
->setMethods( [ 'newBlobStore', 'newSqlBlobStore' ] )
public function provideGetRevisionTextWithLegacyEncoding() {
yield 'Utf8Native' => [
"Wiki est l'\xc3\xa9cole superieur !",
- 'fr',
'iso-8859-1',
(object)[
'old_flags' => 'utf-8',
];
yield 'Utf8Legacy' => [
"Wiki est l'\xc3\xa9cole superieur !",
- 'fr',
'iso-8859-1',
(object)[
'old_flags' => '',
* @covers Revision::getRevisionText
* @dataProvider provideGetRevisionTextWithLegacyEncoding
*/
- public function testGetRevisionWithLegacyEncoding( $expected, $lang, $encoding, $rowData ) {
+ public function testGetRevisionWithLegacyEncoding( $expected, $encoding, $rowData ) {
$blobStore = $this->getBlobStore();
- $blobStore->setLegacyEncoding( $encoding, Language::factory( $lang ) );
+ $blobStore->setLegacyEncoding( $encoding );
$this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
$this->testGetRevisionText( $expected, $rowData );
*/
yield 'Utf8NativeGzip' => [
"Wiki est l'\xc3\xa9cole superieur !",
- 'fr',
'iso-8859-1',
(object)[
'old_flags' => 'gzip,utf-8',
];
yield 'Utf8LegacyGzip' => [
"Wiki est l'\xc3\xa9cole superieur !",
- 'fr',
'iso-8859-1',
(object)[
'old_flags' => 'gzip',
* @covers Revision::getRevisionText
* @dataProvider provideGetRevisionTextWithGzipAndLegacyEncoding
*/
- public function testGetRevisionWithGzipAndLegacyEncoding( $expected, $lang, $encoding, $rowData ) {
+ public function testGetRevisionWithGzipAndLegacyEncoding( $expected, $encoding, $rowData ) {
$this->checkPHPExtension( 'zlib' );
$blobStore = $this->getBlobStore();
- $blobStore->setLegacyEncoding( $encoding, Language::factory( $lang ) );
+ $blobStore->setLegacyEncoding( $encoding );
$this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
$this->testGetRevisionText( $expected, $rowData );
public function testDecompressRevisionText( $legacyEncoding, $text, $flags, $expected ) {
$blobStore = $this->getBlobStore();
if ( $legacyEncoding ) {
- $blobStore->setLegacyEncoding( $legacyEncoding, Language::factory( 'en' ) );
+ $blobStore->setLegacyEncoding( $legacyEncoding );
}
$this->setService( 'BlobStoreFactory', $this->mockBlobStoreFactory( $blobStore ) );
namespace MediaWiki\Tests\Storage;
use InvalidArgumentException;
-use Language;
use MediaWiki\MediaWikiServices;
use MediaWiki\Storage\BlobAccessException;
use MediaWiki\Storage\SqlBlobStore;
$store->setCompressBlobs( $compressRevisions );
}
if ( $legacyEncoding ) {
- $store->setLegacyEncoding( $legacyEncoding, Language::factory( 'en' ) );
+ $store->setLegacyEncoding( $legacyEncoding );
}
return $store;
public function testGetSetLegacyEncoding() {
$store = $this->getBlobStore();
$this->assertFalse( $store->getLegacyEncoding() );
- $this->assertNull( $store->getLegacyEncodingConversionLang() );
- $en = Language::factory( 'en' );
- $store->setLegacyEncoding( 'foo', $en );
+ $store->setLegacyEncoding( 'foo' );
$this->assertSame( 'foo', $store->getLegacyEncoding() );
- $this->assertSame( $en, $store->getLegacyEncodingConversionLang() );
+
+ $this->hideDeprecated( SqlBlobStore::class . '::getLegacyEncodingConversionLang' );
+ $this->assertNull( $store->getLegacyEncodingConversionLang() );
}
/**